//非空判断
function isNull(str){
	if (str == null || str == undefined || str == '') { 
		return true;
		}else{
			return false;			
		} 
}
//数字判断
function isNum(str){
	var reg = /^[0-9]+.?[0-9]*$/;
	if(!reg.exec(str))  {
		   return false;  
	}else{
		return true;
	}  
}
//手机号码判断
function isPhone(str){
	 var re = /^1\d{10}$/;
	    if (re.test(str)) {
	    	return true;
	    } else {
	    	 return false;  
	    }
}
//电话号码判断
function isTel(str){
	 	var re = /0\d{2,3}-\d{7,8}/;
	    if (re.test(str)) {
	    	return true;
	    } else {
	    	 return false;  
	    }
}
//数字或字母组合
function isAccount(str){
	var re = /^[a-zA-Z0-9_-]{4,16}$/;
    if (re.test(str)) {
    	return true;
    } else {
    	 return false;  
    }
}
//年龄判断
function isNum2(str){
	var num=parseFloat(str);
    if (num<100&&num>0) {
    	return true;
    } else {
    	 return false;  
    }
}
//年份判断
function isYear(obj){
	    var re = /^[0-9]+[0-9]*[0-9]*$/ ; 
	   if(!re.test(obj) || obj.length != 4){ 
          return false; 
       }else{
    	   return true;
       } 
}
//获取url中的参数值
function getUrl() {
	  var url = location.search; //获取url中"?"符后的字串
	  var theRequest = new Object();
	  if (url.indexOf("?") != -1) {
	    var str = url.substr(1);
	    strs = str.split("&");
	    for(var i = 0; i < strs.length; i ++) {
	      theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
	    }
	  }
	  return theRequest;
	}
//ajax请求
function postAjax(url,params,callback){
	$.ajax({     
        type: "POST",
        url:url,
        data:params,       
        error: function() {
        	alert("服务器异常");
        },
        success: function(data) {
        	if (data.success){
        		callback(data);
        	}else{
				$.MaxDialog({
					"title":"通知",
					"type":"tips",
					"content":data.msg,
					"time":2
				});
			}
        }
    });
}
function formAjax(url,formId,callback){
	/* start */
	$.ajax({
         type: 'post',
         url: url,
         data: new FormData($(formId)[0]),
         contentType: false,
         processData: false,
         error: function() {
         	alert("服务器异常");
         },
         success: function(data) {
        	 if (data.success){
        		 callback(data);
 			}else{
 				 $.MaxDialog({
     				"title":"通知",
     				"type":"tips",
     				"content":data.msg,
     				"time":2
     		  	 });	
 			}
         }
     });
  	/* end */	
}
/*** js和css按需加载start ***/
function loadJsCss(url, callback ){// 非阻塞的加载 后面的js会先执行
    var isJs = /\/.+\.js($|\?)/i.test(url) ? true : false;
    function onloaded(script, callback){//绑定加载完的回调函数
        if(script.readyState){ //ie
            script.attachEvent('onreadystatechange', function(){
                if(script.readyState == 'loaded' || script.readyState == 'complete'){
                    script.className = 'loaded';
                    callback && callback.constructor === Function && callback();
                }
            });
        }else{
            script.addEventListener('load',function(){
                script.className = "loaded";
                callback && callback.constructor === Function && callback();
            }, false); 
        }
    }
    if(!isJs){ //加载css
        var links = document.getElementsByTagName('link');
        for(var i = 0; i < links.length; i++){//是否已加载
            if(links[i].href.indexOf(url)>-1){ 
                return; 
            }
        }
        var link = document.createElement('link');
        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = url;
        var head = document.getElementsByTagName('head')[0]; 
        head.insertBefore(link,head.getElementsByTagName('link')[0] || null );
    }else{ //加载js
        var scripts = document.getElementsByTagName('script');
        for(var i = 0; i < scripts.length; i++){//是否已加载
            if(scripts[i].src.indexOf(url)>-1 && callback && (callback.constructor === Function) ){ 
            //已创建script
                if(scripts[i].className === 'loaded'){//已加载
                    callback();
                }else{//加载中
                    onloaded(scripts[i], callback);
                }
                return; 
            }
        }
        var script = document.createElement('script');
        script.type = "text/javascript";
        script.src = url; 
        document.body.appendChild(script);
        onloaded(script, callback); 
        
    }
}
/*** js和css按需加载end ***/
